package ru.mirent;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import ru.mirent.exceptions.CustomRuntimeException;
import ru.mirent.handlers.TestExceptionHandler;

@ExtendWith(TestExceptionHandler.class)
public class TestMethodExampleThrowErrorsTest {

    /**
     * AssertionFailedError
     */
    @Test
    void assertionFailedErrorTest() {
        Assertions.assertEquals(1, 2);
    }

    /**
     * RuntimeException
     */
    @Test
    void runtimeExceptionTest() {
        throw CustomRuntimeException.builder().build();
    }

    /**
     * StackOverflowError
     */
    @Test
    void stackOverflowErrorTest() {
        calculateFactorial(1);
//        int i = 5 / 0;
    }

    /**
     * Тестовый метод для проброса исключения StackOverflowError
     */
    private int calculateFactorial(int number) {
        return number * calculateFactorial(number - 1);
    }
}
